package org.jeecg.modules.oa.mapper;

import java.util.Date;
import java.util.List;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.jeecg.modules.oa.entity.OaJournal;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.jeecg.modules.system.entity.SysUser;
import org.springframework.stereotype.Repository;

/**
 * @Description: 工作日志表
 * @Author: jeecg-boot
 * @Date: 2019-09-11
 * @Version: V1.0
 */
@Repository
public interface OaJournalMapper extends BaseMapper<OaJournal> {


    List<OaJournal> listByUser(@Param("page") Page<OaJournal> page, @Param("journal") OaJournal journal);

    List<OaJournal> findListByDateList(@Param("user") SysUser user, @Param("dateList") List<Date> dateList);

    OaJournal findByUserDate(@Param("journal") OaJournal journal);

    List<OaJournal> findPcAllList(@Param("page") Page<OaJournal> page, @Param("journal") OaJournal journal,@Param("departIds") String departIds);

    List<OaJournal> findAllList(@Param("page") Page<OaJournal> page, @Param("journal") OaJournal journal);

    List<OaJournal> findAllListToOutSource(@Param("journal") OaJournal journal);

    @Select("select * from oa_journal where create_by = #{id} AND DATE_FORMAT(create_time,'%Y-%m-%d') = DATE_FORMAT(now(),'%Y-%m-%d') and del_flag = '0' ")
    OaJournal getByCreateByAndToday(@Param("id") String id);

    @Select("SELECT a.id,a.name,DATE_FORMAT(a.create_time,'%Y-%m-%d') as createTimeStr" +
            ",(SELECT count(s.id) FROM oa_comment s WHERE s.topic_id = a.id and s.create_by != #{userId} " +
            " AND s.update_time >= IFNULL (( SELECT update_time  FROM oa_comment_record where topic_id = s.topic_id and user_id = #{userId} ) , '2017-12-06 10:49:59' )  ) AS comment_count " +
            " FROM oa_journal a WHERE a.create_by = #{userId} AND DATE_FORMAT(a.create_time,'%Y-%m') = #{date} ORDER BY a.create_time ASC ")
    List<OaJournal> appFindJournalList(@Param("date") String date,@Param("userId") String userId);
}
